﻿Imports Microsoft.VisualBasic.FileIO
Imports System.IO
Imports System.Threading

Public Class Form1
    Public griddata() As String


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'check that the user only checked 6 tests...and similar checks
        If Me.CheckedListBox1.CheckedItems.Count > 6 Then
            MsgBox("A maximum of 6 tests can be run at a time!")
            Exit Sub
        End If
        If Me.CheckedListBox1.CheckedItems.Count < 1 Then
            MsgBox("Select at least one test")
            Exit Sub
        End If
        If Me.CheckedListBox1.Items.Count = 1 Then
            MsgBox("Pick an actual CPU architecture...")
            Exit Sub
        End If


        'Check that all the paths are "not just blank..."
        'if the log output is blank, assume that the log will not be saved
        If (Me.ConfigLocation.Text = "" Or Me.MTMONFileLocation.Text = "" Or Me.RexecLocation.Text = "" Or Me.vcvars.Text = "") Then
            MsgBox("All paths to files must correctly set. If the log location is not set, no log file will be generated.")
            Exit Sub
        End If



        Me.TextBox1.Text = "Status - Running Tests on " + Str(Me.FunBox.Lines.Length) + " functions."
        'path to the config.h file
        Dim config As String = Me.ConfigLocation.Text
        Dim Configs() As String = File.ReadAllLines(config) 'read whole config file in...

        'path to the MTMONB file
        Dim mtmon As String = Me.MTMONFileLocation.Text
        Dim Mtmons() As String = File.ReadAllLines(mtmon) 'read whole mtmon file in...




        Dim testFile As System.IO.FileInfo
        testFile = My.Computer.FileSystem.GetFileInfo(mtmon)

        'SET REPETITIONS
        Dim reps As Integer = Me.Reps.Value
        'set the reps value in config
        '
        'Configs(24) = "#define REPETITIONS  " + reps.ToString()

        'grab the text from the boxes and such
        Dim Fun(0 To Me.FunBox.Lines.Length) As String
        Fun = Me.FunBox.Lines 'Contains all the functions to be inserted

        Dim Init(0 To Me.InitBox.Lines.Length) As String
        Init = Me.InitBox.Lines 'Contains all initializations

        Dim Incl(0 To Me.DefBox.Lines.Length) As String
        Incl = Me.DefBox.Lines 'Contains all includes needed for the functions to work

        Dim pbox(0 To Me.posttest.Lines.Length) As String
        pbox = Me.posttest.Lines ' contains all the post tests...

        'set config.h tests
        Dim tests As String = ""
        Dim isfirst As Boolean = True
        For Each temp As CPUinst In Me.CheckedListBox1.CheckedItems
            If isfirst <> True Then
                tests = tests + "," + temp.Id.ToString
            Else
                tests = temp.Id.ToString
                isfirst = False
            End If

        Next
        'now tests contains the string to be loaded into the config.h file prior to compilation.
        'insert the config data now (write to file later...)
        For mtindex As Integer = 0 To (Configs.Length - 1)
            If Configs(mtindex) = "//_Set_Tests" Then
                Configs(mtindex) = tests
            End If
            If Configs(mtindex) = "//set_reps" Then
                Configs(mtindex) = "#define REPETITIONS " + Me.Reps.Value.ToString
            End If
            If Configs(mtindex) = "//set_num_threads" Then
                Configs(mtindex) = "#define NUM_THREADS " + Me.threader.Value.ToString
            End If
            If Configs(mtindex) = "//sub_overhead" Then
                If Me.Overhead.Checked = True Then
                    Configs(mtindex) = "#define SUBTRACT_OVERHEAD 1"
                Else
                    Configs(mtindex) = "#define SUBTRACT_OVERHEAD 0"
                End If
            End If
            If Configs(mtindex) = "//set_overhead_reps" Then
                Configs(mtindex) = "#define OVERHEAD_REPETITIONS " + Me.overheadreps.Value.ToString
            End If
            If Configs(mtindex) = "//set_cachelinesize" Then
                Configs(mtindex) = "#define CACHELINESIZE  " + Me.cacheline.Value.ToString
            End If
        Next
        Dim theWriter As New StreamWriter(testFile.DirectoryName + "\config.h")
        For Each currentItem As String In Configs
            theWriter.WriteLine(currentItem)
        Next
        theWriter.Close()



        'Stick these code blocks where they belong in the mtmonb file...

        Dim outputcode(0 To (1 + Init.Length + Incl.Length + Mtmons.Length + Me.posttest.Text.Length)) As String
        Dim isinc As Boolean = 0
        Dim isinit As Boolean = 0
        Dim isfunc As Boolean = 0

        Dim oindex As Integer = 0
        Dim findex As Integer = 0
        For mtindex As Integer = 0 To (Mtmons.Length - 1)
            If (isinc = True And isinit = True And isfunc = True) Then
                If (Mtmons(mtindex) = "//_Post_Function") Then
                    For subdex = 0 To (pbox.Length - 1)
                        outputcode(oindex) = pbox(subdex)
                        oindex = oindex + 1
                    Next
                End If
            ElseIf (isinc = True And isinit = True) Then
                    If (Mtmons(mtindex) = "//_Function") Then
                        findex = oindex
                        oindex = oindex + 1
                        isfunc = 1
                    End If
            ElseIf (isinc) Then
                If (Mtmons(mtindex) = "//_Initialize") Then
                    isinit = 1
                    For subdex = 0 To (Init.Length - 1)
                        outputcode(oindex) = Init(subdex)
                        oindex = oindex + 1
                    Next
                End If
            ElseIf (Mtmons(mtindex) = "//_Include") Then
                isinc = 1
                For subdex = 0 To (Incl.Length - 1)
                    outputcode(oindex) = Incl(subdex)
                    oindex = oindex + 1
                Next
            End If
                outputcode(oindex) = Mtmons(mtindex)
                oindex = oindex + 1
        Next


        'write the new mtmonb file now

        Dim newmtmonpath As String = testFile.DirectoryName + "\MTMonB.cpp"
        Dim theBIGWriter As New StreamWriter(newmtmonpath)
        For Each currentItem As String In outputcode
            theBIGWriter.WriteLine(currentItem)
        Next
        theBIGWriter.Close()

        Dim tbuild As System.IO.FileInfo
        tbuild = My.Computer.FileSystem.GetFileInfo(Me.RexecLocation.Text)
        Dim targetbuild As String = tbuild.DirectoryName + "\Release\c32.exe"


        'make the batch file used to launch compiler
        Dim batch(0 To 5) As String
        batch(0) = "@echo off"
        batch(1) = ":: Load compilation environment - path should be set to "
        batch(2) = "Call ""C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat""" '
        batch(3) = ":: Invoke build environment to handle all files needed for build. c32.sln 'should' not ever need to be modified"
        batch(4) = "Call ""msbuild"" " + """" + Me.RexecLocation.Text + """" + " /p:Configuration=Release /l:FileLogger,Microsoft.Build.Engine;logfile=buildlog.log;append=false;verbosity=normal;encoding=utf-8" 'use the path to the c32.sln file to build the project...
        batch(5) = "Call """ + targetbuild + """"
        Dim thesmallerWriter As New StreamWriter(testFile.DirectoryName + "\Rexec.bat")
        For Each currentItem As String In batch
            thesmallerWriter.WriteLine(currentItem)
        Next
        thesmallerWriter.Close()
        Me.TextBox1.Text = "Status - Running Tests"

        'Run the Benchmark here! yay!

        Dim superlog(0) As String
        Dim otherlog(0) As String
        Dim elog(0) As String
        Dim counter As Integer = 0 'keep track of lines in the output log

        For i As Integer = 0 To Fun.Length - 1
            Me.ProgressBar1.Value = (50 * (i + 1)) / Fun.Length
            'for each function 'Fun(i)', run the test the desired number of times
            outputcode(findex) = Fun(i)

            'write the thing to file...
            Dim theBIGWritern As New StreamWriter(newmtmonpath)
            For Each currentItem As String In outputcode
                theBIGWritern.WriteLine(currentItem)
            Next
            theBIGWritern.Close()


            'Now compile it all...
            Me.ProgressBar1.Value = (100 * (i + 1)) / Fun.Length
            ' New ProcessStartInfo created
            Dim p As New ProcessStartInfo
            ' Specify the location of the binary
            p.FileName = testFile.DirectoryName + "\Rexec.bat"
            ' Use a hidden window
            p.WindowStyle = ProcessWindowStyle.Hidden
            ' Start the process
            Process.Start(p)



Ifnotdead:
            Thread.Sleep(Me.timedelay.Value)
            If Process.GetProcessesByName("c32.exe").Length <> 0 Then
                GoTo Ifnotdead 'Should never be needed, but can prevent the compiler from trying to write to the code file while it is locked if something goes wrong...
            End If



            'grab the logs, add to master log, add other info, and repeat
            'temporary logs are stored at testFile.DirectoryName + log.tmp

            Dim logs() As String = File.ReadAllLines(testFile.DirectoryName + "\log.tmp") 'read mini temp log file in...
            Dim oldlength As Integer = superlog.Length
            Dim otherlength As Integer = otherlog.Length
            ReDim Preserve superlog(oldlength + logs.Length + 1)
            ReDim Preserve otherlog(otherlength + logs.Length)
            'put in the heading for the test
            superlog(oldlength) = "Function tested : " + Fun(i)
            otherlog(otherlength) = "_F_tested_"
            For lindex As Integer = 1 To logs.Length - 1
                otherlog(otherlength + lindex) = logs(lindex)
                superlog(oldlength + lindex + 1) = logs(lindex)
            Next

            Dim elength As Integer = elog.Length
            'grab the logs, add to errorlog...
            Dim blog() As String = File.ReadAllLines(testFile.DirectoryName + "\buildlog.log")
            Dim errlog() As String = File.ReadAllLines(testFile.DirectoryName + "\error.tmp")
            ReDim Preserve elog(elength + blog.Length + errlog.Length + 5)
            elog(counter) = "----------------------------------------------------------------------------------"
            counter = counter + 1
            elog(counter) = "----------------------AGML TIMING SUITE - COMPILER/ERROR LOGS---------------------"
            counter = counter + 1
            elog(counter) = "---------------------------CURRENTLY TESING FUNCTION: ----------------------------"
            counter = counter + 1
            elog(counter) = "---------------------------  " + Fun(i)
            counter = counter + 1
            elog(counter) = "----------------------------------------------------------------------------------"
            counter = counter + 1
            For Each temp In errlog
                elog(counter) = temp
                counter = counter + 1
            Next
            For Each temp In blog
                elog(counter) = temp
                counter = counter + 1
            Next
            'now delete these log files. NO LONGER WANTED. (since stuff gets appended...)
            My.Computer.FileSystem.DeleteFile(testFile.DirectoryName + "\buildlog.log")
            My.Computer.FileSystem.DeleteFile(testFile.DirectoryName + "\error.tmp")
        Next
        Me.TextBox1.Text = "Status - Idle - Testing Complete "
        Me.logbox.Text = ""
        For Each line In superlog
            Me.logbox.Text = Me.logbox.Text + line + vbCrLf
        Next
        For Each line In elog
            Me.errorbox.Text = Me.errorbox.Text + line + vbCrLf
        Next
        Me.ProgressBar1.Value = 0
        ReDim griddata(otherlog.Length)
        Dim ti As Integer = 0
        For Each item In otherlog
            griddata(ti) = item
            ti = ti + 1
        Next

        'now set the fancy schmancy data grid thing...column time!
        Me.DataGridView1.Columns.Clear()
        Me.DataGridView1.Columns.Add("Clock - Warning - dependent on number of processor cores", "Clock - dependent on number of processor cores")
        For Each temp As CPUinst In Me.CheckedListBox1.CheckedItems
            Me.DataGridView1.Columns.Add(temp.HRname, temp.HRname)
        Next
        'set the combo box with the correct function names
        Me.ComboBox2.Items.Clear()
        Me.ComboBox2.Items.AddRange(Fun)


    End Sub

    Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged

    End Sub

    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.ConfigFile.ShowDialog()
        Me.ConfigLocation.Text = Me.ConfigFile.FileName
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.MTMONFile.ShowDialog()
        Me.MTMONFileLocation.Text = Me.MTMONFile.FileName()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.rexecy.ShowDialog()
        Me.RexecLocation.Text = Me.rexecy.FileName()
    End Sub

    Private Sub RexecLocation_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RexecLocation.TextChanged

    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.vcvars32.ShowDialog()
        Me.vcvars.Text = Me.vcvars32.FileName()
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'if the user thinks he is being clever...
        If ComboBox1.SelectedIndex = 2 Then
            Me.CheckedListBox1.Items.Clear()
            Dim temp As CPUinst
            temp = New CPUinst()
            temp.Id = 1
            temp.HRname = "Well, obviously this isn't a valid CPU architecture..."
            Me.CheckedListBox1.Items.Add(temp, False)
        End If

        'for a core 2 duo system, use these instructions...
        If ComboBox1.SelectedIndex = 0 Then

            'clear the listbox
            Me.CheckedListBox1.Items.Clear()
            Dim temp As CPUinst

            ' The first three counters are fixed-function counters having their own register,
            ' The rest of the counters are competing for the same two counter registers.
            temp = New CPUinst()
            temp.Id = 1
            temp.HRname = "Core Clock Cycles"
            Me.CheckedListBox1.Items.Add(temp, False)
            'Dim temp As CPUinst
            temp = New CPUinst()
            temp.Id = 2
            temp.HRname = "Reference Clock Cycles"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 9
            temp.HRname = "Instructions (reference counter)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 10
            temp.HRname = "Instructions"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 11
            temp.HRname = "Instructions involving read, fused count as one"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 12
            temp.HRname = "Instructions involving write, fused count as one"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 13
            temp.HRname = "Instructions without memory"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 20
            temp.HRname = "instruction fetches. (< instructions ?)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 21
            temp.HRname = "instruction fetch stall"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 22
            temp.HRname = "instruction length decoder stalls (length changing prefix)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 23
            temp.HRname = "instruction queue full"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 100
            temp.HRname = "uops retired, fused domain"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 101
            temp.HRname = "fused read uops"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 102
            temp.HRname = "fused write uops"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 103
            temp.HRname = "macrofused uops"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 104
            temp.HRname = "fused uops, all kinds"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 105
            temp.HRname = "uops, not fused"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 110
            temp.HRname = "uops dispatched, unfused domain. Imprecise"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 111
            temp.HRname = "any resource stall"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 115
            temp.HRname = "Stack synchronization uops"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 116
            temp.HRname = "Stack engine additions"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 121
            temp.HRname = "Partial register synchronization, clock cycles"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 122
            temp.HRname = "partial flags stall, clock cycles"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 123
            temp.HRname = "floating point status word stall"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 130
            temp.HRname = "ROB register read stall"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 140
            temp.HRname = "bypass delay to FP unit from int unit"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 141
            temp.HRname = "bypass delay to SIMD/int unit from fp unit (These counters cannot be used simultaneously)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 150
            temp.HRname = "uops port 0. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 151
            temp.HRname = "uops port 1. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 152
            temp.HRname = "uops port 2. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 153
            temp.HRname = "uops port 3. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 154
            temp.HRname = "uops port 4. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 155
            temp.HRname = "uops port 5. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 201
            temp.HRname = "branches taken. (Mask: 1=pred.not taken, 2=mispred not taken, 4=pred.taken, 8=mispred taken)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 204
            temp.HRname = "mispredicted branches"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 204
            temp.HRname = "static branch prediction made"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 210
            temp.HRname = "branch taken bubble 1"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 211
            temp.HRname = "branch taken bubble 2 (these two values must be added)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 310
            temp.HRname = "level 2 cache code fetch"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 311
            temp.HRname = "level 2 cache data fetch"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 320
            temp.HRname = "level 2 cache miss"
            Me.CheckedListBox1.Items.Add(temp, False)
            'end core 2
        End If
        'for an i5/i7 nehalem, use these instructions...
        If ComboBox1.SelectedIndex = 1 Then
            'clear the listbox
            Me.CheckedListBox1.Items.Clear()
            Dim temp As CPUinst
            temp = New CPUinst()
            temp.Id = 1
            temp.HRname = "Core Clock Cycles"
            Me.CheckedListBox1.Items.Add(temp, False)
            'Dim temp As CPUinst
            temp = New CPUinst()
            temp.Id = 2
            temp.HRname = "Reference Clock Cycles"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 9
            temp.HRname = "Instructions (reference counter)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 10
            temp.HRname = "Instructions"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 22
            temp.HRname = "instruction length decoder stalls (length changing prefix)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 24
            temp.HRname = "uops from loop stream detector"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 100
            temp.HRname = "uops retired, unfused domain"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 103
            temp.HRname = "macrofused uops"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 104
            temp.HRname = "uops, fused domain"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 105
            temp.HRname = "microfused uops"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 110
            temp.HRname = "uops dispatched, unfused domain. Imprecise"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 111
            temp.HRname = "any resource stall"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 121
            temp.HRname = "Partial register synchronization, clock cycles"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 122
            temp.HRname = "partial flags stall, clock cycles"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 123
            temp.HRname = "ROB register read stall"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 124
            temp.HRname = "RAT stall, any"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 207
            temp.HRname = "mispredicted branches"
            Me.CheckedListBox1.Items.Add(temp, False)

            temp = New CPUinst()
            temp.Id = 141
            temp.HRname = "bypass delay to SIMD/int unit from fp unit (These counters cannot be used simultaneously)"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 150
            temp.HRname = "uops port 0. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 151
            temp.HRname = "uops port 1. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 152
            temp.HRname = "uops port 2. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 153
            temp.HRname = "uops port 3. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 154
            temp.HRname = "uops port 4. Can only use first counter"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 155
            temp.HRname = "uops port 5. Not Reliable"
            Me.CheckedListBox1.Items.Add(temp, False)

            temp = New CPUinst()
            temp.Id = 156
            temp.HRname = "uops port 0,1,5. Unreliable!"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 157
            temp.HRname = "uops port 2,3,4."
            Me.CheckedListBox1.Items.Add(temp, False)

            temp = New CPUinst()
            temp.Id = 205
            temp.HRname = "static branch prediction made"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 310
            temp.HRname = "level 1 data cache miss"
            Me.CheckedListBox1.Items.Add(temp, False)
            temp = New CPUinst()
            temp.Id = 311
            temp.HRname = "level 2 cache requests"
            Me.CheckedListBox1.Items.Add(temp, False)

        End If
    End Sub

    Public Class CPUinst
        Public Id As Integer
        Public HRname As String ' human readable name
        Public Sub New()
        End Sub

        ' Override tostring to allow use in list/combo/check boxes
        Public Overrides Function ToString() As String
            Return HRname
        End Function

    End Class

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'check that the user only checked 6 tests...
        If Me.CheckedListBox1.CheckedItems.Count > 6 Then
            MsgBox("A maximum of 6 tests can be run at a time!")
            Exit Sub
        End If
        If Me.CheckedListBox1.CheckedItems.Count < 1 Then
            MsgBox("Select at least one test")
            Exit Sub
        End If
        If Me.CheckedListBox1.Items.Count = 1 Then
            MsgBox("Pick an actual CPU architecture...")
            Exit Sub
        End If
        Dim tests As String = ""
        Dim isfirst As Boolean = True
        For Each temp As CPUinst In Me.CheckedListBox1.CheckedItems
            If isfirst <> True Then
                tests = tests + "," + temp.Id.ToString
            Else
                tests = temp.Id.ToString
                isfirst = False
            End If

        Next
        'now tests contains the string to be loaded into the config.h file prior to compilation.



        MsgBox(tests)
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Dim ir As Integer = -1
        Dim scheck As Integer = 0
        Dim itemp As Integer = 0
        Me.DataGridView1.Rows.Clear()
        For Each line In griddata
            If line <> "" Then
                If line = "_F_tested_" Then
                    'go to new array index...
                    ir = ir + 1
                    scheck = 2
                End If
                If scheck = 0 Then
                    Dim temp(6) As String
                    'parse the line into an array
                    temp = Split(line, ",") 'works for actual data lines. 
                    If (ir = Me.ComboBox2.SelectedIndex) Then
                        Me.DataGridView1.Rows.Add(temp)
                    End If
                Else
                    scheck = scheck - 1
                End If
                itemp = itemp + 1
            End If
        Next
    End Sub

    Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Overhead_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Overhead.CheckedChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox(Me.Overhead.Checked)
    End Sub

    Private Sub rexecy_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles rexecy.FileOk

    End Sub
End Class
